package io.github.shang11925.shangweb2.day240902;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;

@WebServlet("/day240902/my-ajax-servlet")
public class MyAjaxServlet implements Servlet {

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        servletResponse.setContentType("text/html");
        PrintWriter writer = servletResponse.getWriter();
        Random random = new Random();
        int num = random.nextInt(100);

        String html = """
                <p>Hallo World! 
                """
                + num +
                """
                </p>
                """
                ;
        writer.write(html);
    }

    @Override
    public String getServletInfo() {
        return "";
    }

    @Override
    public void destroy() {

    }
}
